package org.infodavid.common.services;

import java.util.HashMap;
import java.util.Map;

import junit.framework.Assert;

import org.junit.Test;

import org.infodavid.common.model.criteria.IExtendedSearchCriteria;
import org.infodavid.common.persistence.IDataObject;
import org.infodavid.common.persistence.IDataService;
import org.infodavid.common.services.IEntityService;

/**
 * The Class AbstractServiceTest.
 *
 * @param <T>
 *            the generic type
 * @param <C>
 *            the generic type
 * @param <S>
 *            the generic type
 */
@SuppressWarnings({ "rawtypes" })
public abstract class AbstractServiceTest<L extends IDataObject<Long>, T extends L, C extends IExtendedSearchCriteria, S extends IDataService>
		extends AbstractGenericServiceTest<L, T, C, S> {
	final private static Map<ECrudMethod, String> METHODS;

	static {
		METHODS = new HashMap<ECrudMethod, String>();

		METHODS.put(ECrudMethod.ADD, "add");
		METHODS.put(ECrudMethod.CREATE, "create");
		METHODS.put(ECrudMethod.DELETE, "remove");
		METHODS.put(ECrudMethod.LIST, "findEntities");
		METHODS.put(ECrudMethod.RETRIEVE, "get");
		METHODS.put(ECrudMethod.UPDATE, "update");
	}

	/**
	 * The Constructor.
	 *
	 * @param pService
	 *            the service
	 */
	public AbstractServiceTest(final IEntityService<L, T, C> pService) {
		super(pService, METHODS);
	}

	/*
	 * (non-Javadoc)
	 *
	 * @see org.infodavid.common.services.AbstractGenericServiceTest#getService()
	 */
	@SuppressWarnings("unchecked")
	@Override
	public IEntityService<L, T, C> getService() {
		return (IEntityService<L, T, C>) super.getService();
	}

	/**
	 * Expectations on persistence session.
	 */
	@Override
	protected void expectationsOnSecureService() {
	}

	/**
	 * Test get error handler.
	 */
	@Test
	public void testGetErrorHandler() {
		Assert.assertNotNull("Error handler is null",
				((IEntityService) getService()).getErrorHandler());
	}

	/**
	 * Test get validator.
	 */
	@Test
	public void testGetValidator() {
		Assert.assertNotNull("Validator is null",
				((IEntityService) getService()).getValidator());
	}
}
